'''
@Descripttion: 
@version: 
@encoding: utf-8
@Author: qiurongcan
Date: 2025-09-29 10:23:51
LastEditTime: 2025-09-29 10:46:31
'''



class Solution:

    def findPerkElement(self, nums):

        n = len(nums)
        if n == 1:return 0

        if n == 2 and nums[0] < nums[1]:
            return 1
        elif n == 2 and nums[1] < nums[0]:
            return 0  
        
        window = [-float('inf'), -float("inf"), nums[0]]
        for i in range(1, n + 1):

            if i > n -1:
                window.append(-float("inf"))
                
            else:
                window.append(nums[i])
            window.pop(0)
            if window[0] < window[1] and window[1] > window[2]:
                return i - 1
               
        return -1



